package net.angulardemo.controller;

import java.util.ArrayList;
import java.util.List;

import net.angulardemo.bean.User;

import org.apache.commons.lang3.RandomUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.alibaba.fastjson.JSON;

@Controller
@RequestMapping("base")
public class BaseContorller {
	
	@RequestMapping("index.do")
	public ModelAndView index() {
		ModelAndView mav = new ModelAndView("baseindex");
		List<User> users = new ArrayList<User>();
		for (int i = 1; i < 20 ; i++) {
			int age = RandomUtils.nextInt(20, 40);
			User u = new User("user"+i, age);
			users.add(u);
		}
		mav.addObject("ngusers", users);
		mav.addObject("ngUsersJson", JSON.toJSON(users));
		return mav;
	}
	
	@RequestMapping("listUser.do")
	@ResponseBody
	public List<User> listUser() {
		List<User> users = new ArrayList<User>();
		for (int i = 1; i < 20 ; i++) {
			int age = RandomUtils.nextInt(20, 40);
			User u = new User("user"+i, age);
			users.add(u);
		}
		return users;
	}
	
}
